/* $Id: RoundsPanel.java 39 2009-07-24 22:48:06Z h_m_r@gmx.de $ */
package org.jugger.tournament.gui.view;

import javax.swing.BoxLayout;
import javax.swing.JPanel;

import org.jugger.tournament.model.Round;
import org.jugger.tournament.model.Tournament;

import util.GUIUtils;
import util.I18N;

/**
 * @author Sven Hamer
 */
public class RoundsPanel extends JPanel {

	private static final long serialVersionUID = 1649789741390138011L;
	private Tournament tournament;

	public RoundsPanel(Tournament tournament) {
		setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
		reloadData(tournament);
	}

	public void addRound(String title, Round round) {
		RoundTable roundTable = new RoundTable(tournament, round, true);
		JPanel tablePanel = GUIUtils.createTitledPanelY(title);
		tablePanel.add(roundTable.getTableHeader());
		tablePanel.add(roundTable);
		add(tablePanel);
	}

	public void reloadData(Tournament tournament) {
		this.removeAll();
		this.tournament = tournament;

		int currentRoundNumber = tournament.countFinishedRounds()+1;

		addRound(
				I18N.__("numberedRound", new Object[]{currentRoundNumber}) + " (" + I18N.__("currentMatches") + ")",
				tournament.getRound(currentRoundNumber)
		);

		for(int roundNumber=tournament.countFinishedRounds(); roundNumber>0; --roundNumber) {
			addRound(
					I18N.__("numberedRound", new Object[]{roundNumber}),
					tournament.getRound(roundNumber)
			);
		}
	}
}
